 <?php
// 记录控制器
class HistoryAction extends CommonAction {
	/**
	 * [leaveData description]请假记录
	 * @return [type] [description]
	 */
	public function leaveData(){
		$model=new Model();
		$result = array();
		$list = array();
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
	    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
	    $data=$model->table("oa_process op,oa_leave ol")->where("op.process_id=ol.leave_process_id and leave_state=3")->page($page,$rows)->order("op.process_time desc")->select();
	    foreach ($data as $value) {
            $value['process_begin_id']=$this->getOneEmployeName($value['process_begin_id']);
            $list[]=$value;
        }
		$result['rows']=$list;
		$result['total']=$model->table("oa_process op,oa_leave ol")->where("op.process_id=ol.leave_process_id and leave_state=3")->count();
		echo json_encode($result);
	}

	/**
	 * [getGoodsData description]领用物品历史数据
	 * @return [type] [description]
	 */
	public function getGoodsData(){
		$model=new Model();
		$result = array();
		$list = array();
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
	    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
	    $data=$model->table("oa_process op,oa_goods og")->where("op.process_id=og.goods_process_id and goods_state=3 and goods_type='1'")->page($page,$rows)->order("op.process_time desc")->select();
	    foreach ($data as $value) {
            $value['process_begin_id']=$this->getOneEmployeName($value['process_begin_id']);
            $value['goods_type']='物品领取申请';
            $list[]=$value;
        }
		$result['rows']=$list;
		$result['total']=$model->table("oa_process op,oa_goods og")->where("op.process_id=og.goods_process_id and goods_state=3 and goods_type='1'")->count();
		echo json_encode($result);
	}

	/**
	 * [getGoodsDetail description]获取具体物品
	 * @return [type] [description]
	 */
	public function getGoodsDetail(){
		$result = array();
		$goods_id=$_GET['goods_id'];
		$getgoods=M('Getgoods');
		$result['rows']=$getgoods->where("getgoods_goods_id='".$goods_id."'")->select();
		echo json_encode($result);
	}

	/**
	 * [buyGoodsData description]购买物品历史数据
	 * @return [type] [description]
	 */
	public function buyGoodsData(){
		$model=new Model();
		$result = array();
		$list = array();
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
	    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
	    $data=$model->table("oa_process op,oa_goods og")->where("op.process_id=og.goods_process_id and goods_state=3 and goods_type='2'")->page($page,$rows)->order("op.process_time desc")->select();
	    foreach ($data as $value) {
            $value['process_begin_id']=$this->getOneEmployeName($value['process_begin_id']);
            $value['goods_type']='购买物品申请';
            $list[]=$value;
        }
		$result['rows']=$list;
		$result['total']=$model->table("oa_process op,oa_goods og")->where("op.process_id=og.goods_process_id and goods_state=3 and goods_type='2'")->count();
		echo json_encode($result);
	}


	/**
	 * [buyGoodsDetail description]获取具体物品
	 * @return [type] [description]
	 */
	public function buyGoodsDetail(){
		$result = array();
		$goods_id=$_GET['goods_id'];
		$buygoods=M('Buygoods');
		$result['rows']=$buygoods->where("buygoods_goods_id='".$goods_id."'")->select();
		echo json_encode($result);
	}

	/**
	 * [repairData description]物品维修历史数据
	 * @return [type] [description]
	 */
	public function repairData(){
		$model=new Model();
		$result = array();
		$list = array();
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
	    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
	    $data=$model->table("oa_process op,oa_goods og")->where("op.process_id=og.goods_process_id and goods_state=3 and goods_type='3'")->page($page,$rows)->order("op.process_time desc")->select();
	    foreach ($data as $value) {
            $value['process_begin_id']=$this->getOneEmployeName($value['process_begin_id']);
            $value['goods_type']='物品维修申请';
            $list[]=$value;
        }
		$result['rows']=$list;
		$result['total']=$model->table("oa_process op,oa_goods og")->where("op.process_id=og.goods_process_id and goods_state=3 and goods_type='3'")->count();
		echo json_encode($result);
	}


	/**
	 * [repairDetail description]获取具体物品
	 * @return [type] [description]
	 */
	public function repairDetail(){
		$result = array();
		$goods_id=$_GET['goods_id'];
		$repair=M('Repair');
		$result['rows']=$repair->where("repair_goods_id='".$goods_id."'")->select();
		echo json_encode($result);
	}

	/**
	 * [documentData description]公文记录
	 * @return [type] [description]
	 */
	public function documentData(){
		$model=new Model();
		$result = array();
		$list = array();
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
	    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
	    $data=$model->table("oa_process op,oa_document od")->where("op.process_id=od.document_process_id and document_state=3")->page($page,$rows)->order("op.process_time desc")->select();
	    foreach ($data as $value) {
            $value['process_begin_id']=$this->getOneEmployeName($value['process_begin_id']);
            $list[]=$value;
        }
		$result['rows']=$list;
		$result['total']=$model->table("oa_process op,oa_document od")->where("op.process_id=od.document_process_id and document_state=3")->count();
		echo json_encode($result);
	}
}